package middleware

import (
	"github.com/gin-gonic/gin"
	"kf/models/dao"
)

type IpBlack struct {
	IpBlackDao dao.IpBlackDao
}

func (ipBlack *IpBlack) Ipblack(c *gin.Context) {
	ip := c.ClientIP()
	if ip == "" {
		c.JSON(200, gin.H{
			"code": 400,
			"msg":  "未获取到IP",
		})
		c.Abort()
		return
	}
	ipblack := ipBlack.IpBlackDao.FindIp(ip)
	if ipblack.IP != "" {
		c.JSON(200, gin.H{
			"code": 400,
			"msg":  "IP已被加入黑名单",
		})
		c.Abort()
		return
	}
}
